package com.sdry.web.controller.permission;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sdry.entity.permission.UpmsStaff;
import com.sdry.entity.permission.UpmsStaffLog;
import com.sdry.service.permission.UpmsStaffLogService;
import com.sdry.utils.DateJsonValueProcessor;
import com.sdry.utils.ResponseUtil;


/**
*
* @ClassName:UpmsStaffLogController
* @Description:日志
* @Author tdd
* @Date Mon Jul 30 15:23:44 CST 2018
* @version 1.0
*/
@Controller
@RequestMapping("/upmsStaffLog")
public class StaffLogController{
   /**注入日志Server*/
   @Resource UpmsStaffLogService  upmsStaffLogService;
   /**
    * 条件分页查询
    * @param upmsStaffLog 日志实体类
    * @param response
    * @return
    * @throws Exception
    */
   @RequestMapping("/list")
   public String list(String sname,UpmsStaffLog upmsStaffLog,HttpServletResponse response) throws Exception{
   	UpmsStaff upmsStaff = new UpmsStaff();
   	upmsStaff.setSname(sname);
	upmsStaffLog.setUpmsStaff(upmsStaff);
	/*
   	* 条件分页查询内容
   	*/
   	List<UpmsStaffLog> list = upmsStaffLogService.findPageByMution(upmsStaffLog);
   	/*
   	* 条件查询总条数
   	*/
   	Integer total = upmsStaffLogService.selectCountByMution(upmsStaffLog);

   	/*
   	* 转为json数据传至页面
   	*/
   	JsonConfig jsonConfig = new JsonConfig();
   	jsonConfig.registerJsonValueProcessor(Date.class, new DateJsonValueProcessor("yyyy-MM-dd HH:mm:ss"));
   	//创建result
   	JSONObject result = new JSONObject();
   	//转json数据
   	JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
   	//添加入result
   	result.put("rows", jsonArray);
   	result.put("total", total);
   	//发送result
   	ResponseUtil.write(response, result);
   	return null;
   }
   /**
    * 添加日志
    * @param upmsStaffLog 日志实体类
    * @param session
    * @param response
    * @return
    * @throws Exception
   */
   @RequestMapping("/add")
   public void add(UpmsStaffLog upmsStaffLog,HttpSession session, HttpServletResponse response) throws Exception{
       /*
        * 添加返回id
       */
       Long id = upmsStaffLogService.insert(upmsStaffLog);
       if (null != id) {
           response.getWriter().print("1");
       }else{
           response.getWriter().print("0");
       }
   }
   /**
    * 多删除
    * @param ids 日志id累加字符串
    * @param session
    * @param response
    * @return
    * @throws Exception
   */
   @RequestMapping("/delete")
   public void delete(String ids,HttpSession session, HttpServletResponse response) throws Exception{
       System.out.println(ids);
       ids=ids.replace("'",""); 
       /*
        * 多删除返回影响行数
       */
       Integer count = upmsStaffLogService.delete(ids);
       if (count >= 1) {
           response.getWriter().print("1");
       }else{
           response.getWriter().print("0");
       }
   }
   /**
    * 条件查询日志
    * @param upmsStaffLog 日志实体类
    * @return 日志实体类集合
   */
   @RequestMapping("/queryAll")
   @ResponseBody
   public List<UpmsStaffLog> queryAllByMution(UpmsStaffLog upmsStaffLog){
       List<UpmsStaffLog> list = upmsStaffLogService.queryAllByMution(upmsStaffLog);
       return list;
   }
   /**
    * 根据id查日志
    * @param id 日志id
    * @return 日志实体类
   */
   @RequestMapping("/queryById")
   @ResponseBody
   public UpmsStaffLog queryById(Long id){
       UpmsStaffLog upmsStaffLog = upmsStaffLogService.queryById(id);
       return upmsStaffLog;
   }
   /**
    * 修改部门
    * @param upmsStaffLog 日志实体类
    * @param session
    * @param response
    * @return
    * @throws Exception
   */
   @RequestMapping("/update")
   public void update(UpmsStaffLog upmsStaffLog,HttpSession session, HttpServletResponse response) throws Exception{
       /*
        * 修改返回影响行数
       */
       Integer count = upmsStaffLogService.update(upmsStaffLog);
       if (count >= 1) {
           response.getWriter().print("1");
       }else{
           response.getWriter().print("0");
       }
   }
}
